﻿using UnityEngine;
using System.Collections;

public class Player1Controller1 : MonoBehaviour {
	
	public bool moveLeft1 = false;
	public bool moveRight1 = false;
	public bool moveUp1 = false;
	public bool moveDown1 = false;
	public bool shootBullet1 = false;
	
	public float playerMaxSpeed = 5f;
	bool facingRight = false;
	bool facingLeft = false;
	bool facingUp = true;
	bool facingDown = false;
	public Transform masterObject;
	public GameObject masterObject2;

	public float playerCurrentBullet = 100;

	public Transform shotSpawn1;
	
	public Vector3 playerScale;
	
	public float playerMaxHealth1 = 3;
	public float playerCurrentHealth = 3;
	
	public SpriteRenderer playerImage;
	
	private GameObject Player2;
	
	private float move = 0;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () 
	{

		if (shootBullet1==true) 
		{
			Instantiate(masterObject2, shotSpawn1.position, shotSpawn1.rotation);
			Debug.Log ("Its power is over 9000");
			//masterObject.transform.localScale = Player1.localScale;
		}

		if (playerMaxHealth1 == 0) {
			Application.LoadLevel ("GameOve2"); 
		}
	}
	
	void FixedUpdate () {
		if(moveLeft1){
			transform.Translate(0.05f,0,0);
		}
		else if(moveRight1)
			transform.Translate(-0.05f,0,0);
		else if(moveUp1)
			transform.Translate(0,0.05f,0);
		else if(moveDown1)
			transform.Translate(0,-0.05f,0);
	}

	void OnCollisionEnter2D(Collision2D coll){
		if (coll.gameObject.tag == "Player2Bullet"){
			playerMaxHealth1--;
		}
		if (coll.gameObject.tag == "Astarod1"){
			playerMaxHealth1--;
		}
	}
}